Using the SQL Genie

Description

The SQL Genie helps you write SQL expressions. This page contains some pointers on how to use it.

The SQL Genie helps you write SQL expressions. To start the SQL Genie:

  1. Create a SQL::Connection object and open a connection to AlphaSports.mdb.

  2. Pass the SQL::Connection object to the SQL_Query_Builder() function.

    dim qry as C
    dim conn as SQL::Connection
    conn.open("{A5API=Access,FileName='C:\Program Files\a5v8\MDBFiles\Alphasports.mdb',UserName='Admin'}")
    qry = sql_query_builder(conn)
    This opens the SQL Genie and displays its Tables tab.
  3. Click Add Table to display the Add Table dialog.

  4. Select "Customer" and click OK. When you return to the SQL Genie, you will see the start of your SQL expression in the SQL window.

    images/CST_SQL_Genie_select_table.png
  5. Display the Columns tab.

  6. Select the "FIRSTNAME", "LASTNAME", "PHONE", and "FAX" entries in the Available Columns list and click the 'right arrow' icon to move them into the Selected Columns list. Note how the SELECT statement in the SQL window updates to reflect your latest choices.

    images/CST_SQL_Genie_select_columns.gif
  7. Display the Filter tab.

  8. Click the 'up arrow' icon to display the Select Column or Expression dialog.

  9. Select "PHONE" in the Columns list and click OK. Note how the SELECT statement in the SQL window updates to reflect your latest choices.

    images/CST_SQL_Genie_define_filter.gif
  10. Click the 'down arrow' icon to display the Operator list.

  11. Select "is not null".

    images/CST_SQL_Genie_define_filter_2.gif
  12. Display the Order tab.

  13. Select "LASTNAME" in the Available Columns list and click the 'right arrow' icon.

  14. Select "FIRSTNAME" in the Available Columns list and click the 'right arrow' icon . Note how the SQL window displays the latest version of the SQL SELECT statement.

  15. Click OK to return to the Interactive window.

    images/CST_SQL_Genie_define_order.gif
  16. Execute the query and list the data you get back. The data contains 4 fields, filtered, and ordered as you specified.

    conn.execute(qry)
    dim data as C
    data = conn.resultset.ToString()
    ? data
    = Winston Abrams (402) 555-6112
    Randi Adams (808) 555-6721 (808) 555-7500
    John Baker (914) 555-8400
    Tom Barber (914) 555-8700
    Jeffrey Bernstein (914) 555-0987
    George Boschetti (803) 555-6143
    ...
  17. Close the connection.

    conn.close()

See Also